import { IThemeMainService, ThemeMainService } from './services/themeMainService';
import { CodeApplication } from './app';
import { SyncDescriptor } from './core/descriptors';
import { IInstantiationService } from './core/instantiation';
import { InstantiationService } from './core/instantiationService';
import { ServiceCollection } from './core/serviceCollection';
import { IStateService, StateService } from './services/stateService';

class CodeMain {
  main(): void {
    this.startup();
  }

  private async startup(): Promise<void> {

    const instantiationService = this.createServices();

    // TODO: 启动初始化处理流程
    await instantiationService.invokeFunction(async (accessor: any) => {

      const stateService = accessor.get(IStateService);
      console.log("stateService: ", stateService.getItem())
      
    });

    // 启动
    await instantiationService.invokeFunction(async () => {
      return (instantiationService.createInstance(CodeApplication as any) as any).startup();
    });
  }

  private createServices(): IInstantiationService {
    const services = new ServiceCollection();

    services.set(IStateService, new StateService());
    services.set(IThemeMainService, new SyncDescriptor(ThemeMainService));

    return new InstantiationService(services, true)
  }
}

export default CodeMain;